Imports System.Windows.Forms
Imports Vintasoft.Pdf
Imports Vintasoft.Pdf.Security

Namespace Pdf.Security
	Public Partial Class SecurityPropertiesForm
		Inherits Form
		Const NotAllowed As String = "Not Allowed"

		Public Sub New(document As PdfDocument)
			InitializeComponent()

			SyncLock document
				If document.IsEncrypted Then
					encryptionLabel.Text = document.EncryptionSystem.ToString()

					authorizationResultLabel.Text = document.AuthorizationResult.ToString()

					If document.EncryptionSystem.ContainsUserPassword Then
						userPasswordLabel.Text = "Yes"
					End If
					If document.EncryptionSystem.ContainsOwnerPassword Then
						ownerPasswordLabel.Text = "Yes"
					End If

					Dim permissions As UserAccessPermissions = document.EncryptionSystem.UserPermissions

					If (permissions And UserAccessPermissions.AssembleDocument) = 0 Then
						assembleDocumentLabel.Text = NotAllowed
					End If

					If (permissions And UserAccessPermissions.ExtractTextAndGraphics) = 0 Then
						extractTextAndGraphicsLabel.Text = NotAllowed
					End If

					If (permissions And UserAccessPermissions.FillInteractiveFormFields) = 0 Then
						fillInteractiveFormFieldsLabel.Text = NotAllowed
					End If

					If (permissions And UserAccessPermissions.ModifyAnnotations) = 0 Then
						modifyAnnotationLabel.Text = NotAllowed
					End If

					If (permissions And UserAccessPermissions.ModifyContents) = 0 Then
						modifyContentsLabel.Text = NotAllowed
					End If

					If (permissions And UserAccessPermissions.PrintDocumentInLowResolution) = 0 Then
						printingLabel.Text = NotAllowed
					Else
						If (permissions And UserAccessPermissions.PrintDocumentInHighResolution) = 0 Then
							printingLabel.Text += " (Low Resolution)"
						Else
							printingLabel.Text += " (High Resolution)"
						End If
					End If
				Else
					encryptionLabel.Text = "No Encryption"
				End If
			End SyncLock
		End Sub

		Private Sub buttonOk_Click(sender As Object, e As EventArgs)
			DialogResult = DialogResult.OK
		End Sub
	End Class
End Namespace
